<%@page import="com.shopping.util.StringUtil"%>
<%@ page language="java"  pageEncoding="UTF-8" %>
<%@ page import="com.shopping.modean.*" %>
<%@ page import="com.shopping.service.*" %>
<%@ page import="java.util.*" %>
<%@  include file="_session_check.jsp" %>

<%
  request.setCharacterEncoding("UTF-8");
  String action = request.getParameter("action");
  String id = request.getParameter("id");
  if(action != null && action.trim().equals("productAdd")) {
	  String descr = request.getParameter("descr");
	  String normalPrice = request.getParameter("normal_price");
	  String memberPrice = request.getParameter("member_price");
	  String categoryId = request.getParameter("category_id");
	  
	  Product p = new Product();
	  p.setDescr(descr);
	  p.setNormalPrice(Double.valueOf(normalPrice));
	  p.setMemberPrice(Double.valueOf(memberPrice));
	  p.setCategoryId(Integer.valueOf(categoryId));
	  
	  if(StringUtil.isEmpty(id)) {
		  ProductService.getInstance().add(p);
	  } else {
		  p.setId(Integer.valueOf(id));
		  ProductService.getInstance().update(p);
	  }
	  response.sendRedirect("product_list.jsp");
	  return;
  }

%>

<!DOCTYPE html>
<html>
<head>
  <title>添加商品</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  
  <script type="text/javascript">
  	function toListCategory() {
  		var form = document.getElementById("category_add");
  		form.setAttribute("action","category_list.jsp");
  		form.submit();
  	}
  
  </script>	
  	  
</head>

<body>

  
  
</body>
</html>